<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>关于公司</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/formSelects/formSelects-v4.css"/>

    <style>
        .js-a, js-b {
            display: none
        }
    </style>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">

                <div class="layui-form-item" hidden>
                    <label class="layui-form-label w-auto">关于公司id:</label>
                    <div class="layui-input-inline mr0">
                        <% if(companyDetails==null){ %>
                        <input id="id" class="layui-input" type="text"/>
                        <% }else{ %>
                        <input id="id" class="layui-input" type="text" value="${companyDetails.id}"/>
                        <% } %>
                    </div>
                </div>

                <div class="layui-form-item js-a ">
                    <div class="layui-inline">
                        <button id="btnPost" class="layui-btn layui-btn-normal" style="margin-bottom: 20px;">发布</button>
                    </div>
                    <div class="layui-input-block" style="margin: 0">
                        <% if(companyDetails==null){ %>
                        <textarea class="layui-textarea" name="content" id="content" lay-verify="article_desc" cols="600"></textarea>
                        <% }else{ %>
                        <textarea class="layui-textarea" name="content" id="content" lay-verify="article_desc" cols="600">
                            ${companyDetails.content}
                        </textarea>
                        <% } %>
                    </div>
                </div>
                <div class="layui-form-item js-b ">
                    <div class="layui-inline">
                        <button id="btnEdit"  class="layui-btn layui-btn-normal" style="margin-bottom: 20px;">编辑</button>
                    </div>
                    <div class="layui-input-block" style="margin: 0">
                        <div class="content1">
                            <% if(companyDetails!=null){ %>
                            ${companyDetails.content}
                            <% } %>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>


<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>

<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'upload', 'jquery', 'formSelects' ,'excel','layedit'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var formSelects = layui.formSelects;
        var layEdit = layui.layedit;

        var haveId = $("#id").val();

        $(".js-a,.js-b").hide();
        $(haveId ? ".js-b" : ".js-a").show();
        console.log(haveId);


        //富文本编辑器 layedit

        layEdit.set({
            uploadImage: {
                url: '/upload/uploadLayeditFile',  //上传方法名
                type: 'post'
            },
            codeConfig: {
                hide: true,  //是否显示编码语言选择框
                default: 'javascript' //hide为true时的默认语言格式
            },
            tool: [ 'undo', 'redo', 'code', 'strong', 'italic', 'underline', 'del', 'addhr', '|', 'removeformat', 'fontFomatt', 'fontfamily', 'fontSize', 'fontBackColor', 'colorpicker', 'face'
                , '|', 'left', 'center', 'right', '|', 'link', 'unlink',  'image',  'attachment', '|'
                , 'table', 'customlink'
                , 'fullScreen', 'preview'
            ],
            height: '90%'
        });

        var index=layEdit.build('content');//构建编辑器
        form.verify({
            article_desc: function(value){
                layEdit.sync(index);
            }
        });

        // 发布
        $('#btnPost').click(function () {
            var url = haveId ? '/admin/content/update' : '/admin/content/add';
            //var content = $('#content').val();
            var content = layEdit.getContent(index);
            var id = $('#id').val();
            var date={};
            if(haveId){
                date={
                    content: content,
                    id:id
                }
            }else{
                date={
                    content: content,
                    type:2
                }
            }
            ajaxCommon(url, date);
            //console.log(content);
            window.location.reload();
        });

        // 编辑
        $('#btnEdit').click(function () {
            $(".js-b").hide();
            $('.js-a').show();
        });


    })

</script>

</body>
</html>